import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;

// 数据列表
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords,
    department: queryParams.department
  }
  return request({
    url: '/getPaperList',
    method: 'post',
    data: data
  })
}

// 新增
export function addData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId,
      title: val.title, //试卷名称
      typeVal: val.typeVal, // 试卷类型
      rules: val.rules, //组卷规则
      theNum: val.theNum, //试题数量
      duration: val.duration, //试卷考试时长
      totalScore: val.totalScore, //试卷总分
      passLine: val.passLine, //试卷及格线
      publisherId: val.publisherId, //发布人id
      publisher: val.publisher, //发布人
      questionCategoryId: val.questionCategoryId, //试题分类 id
      questionCategory: val.questionCategory, //试题分类
      paperContent: val.paperContent, //试卷内容（如果 试卷类型 是 固定试题 时使用，直接存放具体题目）
    }
  }
  return request({
    url: '/addPaper',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getPaperData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent: {
      theid: val.theid, //id
      title: val.title, //试卷名称
      typeVal: val.typeVal, // 试卷类型
      rules: val.rules, //组卷规则
      duration: val.duration, //试卷考试时长
      totalScore: val.totalScore, //试卷总分
      passLine: val.passLine, //试卷及格线
      publisherId: val.publisherId, //发布人id
      publisher: val.publisher, //发布人
      paperContent: val.paperContent, //试卷内容（如果 试卷类型 是 固定试题 时使用，直接存放具体题目）
    }
  }
  return request({
    url: '/updatePaper',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delPaper',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultiplePaper',
    method: 'post',
    data: data
  })
}

// 选择题库下拉框
export function getSelect() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getPaperComboBox',
    method: 'post',
    data: data
  })
}
// 选择题库数据列表
export function questbank(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords,
    category: queryParams.category, //试题分类
    theType: queryParams.theType, //题型 1-单选 2-多选 3-判断 4-填空
  }
  return request({
    url: '/getQuestionsList',
    method: 'post',
    data: data
  })
}

// 修改启用状态  enable 启用状态  0-未启用 1-已启用
export function getEnable(theid, enable) {
  const data = {
    projectContent: {
      theid,
      enable
    }
  }
  return request({
    url: '/changeEnablePaper',
    method: 'post',
    data: data
  })
}

// 查看试卷
export function getPaper(theid) {
  const data = {
    theid
  }
  return request({
    url: '/seeTestPaper',
    method: 'post',
    data: data
  })
}